<template>
  <!-- 无形资产摊销详情 -->
  <!-- {
        text: '导出',
        type: 'info',
        icon: 'export',
        trigger: 'export',
      },
      {
        text: '打印',
        type: 'info',
        trigger: 'print',
      }, -->
  <Drawer
    title="详情"
    :visible="wxzcVisible"
    :header-color="'#e7ecf8'"
    width="70%"
    :footer-btns="[
      {
        text: '取消',
        type: 'info',
        trigger: 'cancel',
      },
    ]"
    @cancel="cancel"
    @print="print"
    @export="exportBtn"
  >
    <div class="drawer-box">
      <div class="box-title">无形资产摊销详情</div>
      <div class="box-table">
        <el-table
          ref="tableref"
          v-loading="tableLoading"
          :data="tableWxzcData"
          border
          :header-cell-style="{
            background: '#fafafa',
            borderColor: '#e7ecf8',
            color: '#555555',textAlign:'center'
          }"
          header-row-class-name="ck-table-header"
          row-class-name="ck-table-row"
          size="small"
          height="100%"
          style="width: 100%"
          show-summary
          :summary-method="getSummaries"
        >
          <el-table-column
            align="center"
            type="index"
            label="序号"
            width="60"
          />
          <el-table-column prop="cardnum" label="无形资产代码" />
          <el-table-column prop="cardname" label="无形资产名称" />
          <el-table-column prop="usestartdate" label="启用日期" />
          <!-- <el-table-column prop="originalvalue" label="原值" />
          <el-table-column prop="monthlimit" label="折旧月限" /> -->
          <el-table-column prop="value" label="折旧额" align="right">
            <template slot-scope="scope">
              {{ scope.row.value |numberToCurrency}}
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </Drawer>
</template>
<script>
import { listDrugCostByPDeptCode } from "@/utils/apis/report";
export default {
  props: {
    // 接收父组件传来的值
    wxzcVisible: Boolean,
    tableWxzcData: Array,
  },
  data() {
    return {
      total: 0,
      pageSize: 20,
      currentPage: 1,
      tableData: [],
      tableLoading: false,
    };
  },
  inject: ["tableRoot"],
  mounted() {
    // this.getData();
  },
  updated() {
    if (this.$refs.tableref) {
      this.$refs.tableref.doLayout();
    }
  },
  methods: {
    getData() {
      const date = this.tableRoot.newParamList.yearMonth
      // const year =
      //   this.tableRoot.newParamList.yearMonth &&
      //   this.tableRoot.newParamList.yearMonth.substr(0, 4);
      // const month =
      //   this.tableRoot.newParamList.yearMonth &&
      //   this.tableRoot.newParamList.yearMonth.substr(5);
      let param = {
        // month: month,
        // year: year,
        yard: "1",
        starYear: this.$moment(date[0]).format('YYYY'),
        endYear: this.$moment(date[1]).format('YYYY'),
        starMonth: this.$moment(date[0]).format('MM'),
        endMonth: this.$moment(date[1]).format('MM'),
      };
      this.tableLoading = true;
      listDrugCostByPDeptCode(param, this.tableRoot.deptCode).then((res) => {
        if (res.data.code === 200) {
          this.tableLoading = false;
          this.tableData = res.data.data;
        }
      });
    },
    // 关闭抽屉
    cancel() {
      this.$emit("handleCloseWxzc", { wxzcVisible: false });
    },
    // 导出
    exportBtn() {
      console.log("导出");
    },
    // 打印
    print() {
      console.log("打印");
    },
    // 分页
    handleSizeChange(val) {
      this.pageSize = val;
      this._getData();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this._getData();
    },
    // 指定列求和
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总计";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        if (index >= 4) {
          if (!values.every((value) => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index] = sums[index].toFixed(2);
            // sums[index] += " 元";
          } else {
            sums[index] = "N/A";
          }
        }
      });
      return sums;
    },
  },
};
</script>
<style lang="less" scoped>
.el-table--mini,
.el-table--small,
.el-table__expand-icon {
  font-size: 14px !important;
}

.ck-table-header {
  th {
    background: #fafafa !important;
    height: 48px;
    color: #555555 !important;
  }
}
.pagenation-box {
  display: flex;
  padding-top: 2px;
  justify-content: flex-end;
}
.drawer-box {
  height: 100%;
}
.box-title {
  height: 44px;
  background: #f6f9fe;
  border-bottom: 1px solid #e7ecf8;
  font-size: 16px;
  color: #555555;
  line-height: 44px;
  padding-left: 10px;
  box-sizing: border-box;
}
.box-table {
  padding: 14px 10px 14px 10px;
  height: calc(100% - 78px);
  box-sizing: border-box;
  overflow: hidden;
}
</style>
